// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... namespace LargoCommon.Music { using Abstract; using JetBrains.Annotations; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; /// /// Energy Change. /// public sealed class EnergyChange : AbstractChange { #region Constructors /// /// Initializes a new instance of the class. /// [UsedImplicitly] public EnergyChange() { } /// /// Initializes a new instance of the class. /// /// The given change. public EnergyChange(XElement xchange) : base(xchange) { Contract.Requires(xchange != null); if (xchange == null) { return; } this.BeatLevel = XmlSupport.ReadByteAttribute(xchange.Attribute("BeatLevel")); this.ToneLevel = XmlSupport.ReadByteAttribute(xchange.Attribute("ToneLevel")); this.RhythmicTension = XmlSupport.ReadByteAttribute(xchange.Attribute("RhythmicTension")); this.MelodicDirection = XmlSupport.ReadByteAttribute(xchange.Attribute("MelodicDirection")); this.HarmonicPotential = XmlSupport.ReadByteAttribute(xchange.Attribute("HarmonicPotential")); this.ChangeType = MusicalChangeType.Energy; } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. public EnergyChange(int givenBar, int givenLine) : base(givenBar, givenLine, MusicalChangeType.Energy) { } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. /// The given beat level. /// The given tone level. /// The given rhythmic tension. public EnergyChange(int givenBar, int givenLine, byte givenBeatLevel, byte givenToneLevel, byte givenRhythmicTension) : base(givenBar, givenLine, MusicalChangeType.Energy) { this.BeatLevel = givenBeatLevel; this.ToneLevel = givenToneLevel; this.RhythmicTension = givenRhythmicTension; } #endregion #region Properties - Xml /// /// Gets Xml representation. /// /// /// Property description. /// public override XElement GetXElement { get { var change = base.GetXElement; change.Add(new XAttribute("BeatLevel", this.BeatLevel)); change.Add(new XAttribute("ToneLevel", this.ToneLevel)); change.Add(new XAttribute("RhythmicTension", this.RhythmicTension)); change.Add(new XAttribute("MelodicDirection", this.MelodicDirection)); change.Add(new XAttribute("HarmonicPotential", this.HarmonicPotential)); return change; } } #endregion #region Properties /// /// Gets or sets the beat level. /// /// /// The beat level. /// [UsedImplicitly] public byte BeatLevel { get; set; } /// /// Gets or sets the tone level. /// /// /// The tone level. /// [UsedImplicitly] public byte ToneLevel { get; set; } /// /// Gets or sets the rhythmic tension. /// /// /// The rhythmic tension. /// [UsedImplicitly] public byte RhythmicTension { get; set; } /// /// Gets or sets the melodic direction. /// /// /// The melodic direction. /// [UsedImplicitly] public byte MelodicDirection { get; set; } /// /// Gets or sets the harmonic potential. /// /// /// The harmonic potential. /// [UsedImplicitly] public byte HarmonicPotential { get; set; } #endregion #region Public methods /// /// Clones this instance. /// /// Returns object. public override object Clone() { var tmc = new EnergyChange(this.BarNumber, this.LineIndex) { BeatLevel = this.BeatLevel, ToneLevel = this.ToneLevel, RhythmicTension = this.RhythmicTension, MelodicDirection = this.MelodicDirection, HarmonicPotential = this.HarmonicPotential }; //// tmc.BlockModel = this.BlockModel; return tmc; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendFormat(CultureInfo.CurrentCulture, base.ToString()); s.Append("," + this.BeatLevel); s.Append("," + this.ToneLevel); s.Append("," + this.RhythmicTension); s.Append("," + this.MelodicDirection); s.Append("," + this.HarmonicPotential); return s.ToString(); } #endregion } }